﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// 所有的库存查询，根据入库，可以查询入库的WB04
    /// </summary>
    public partial class UIWGBST : ViewBase
    {
        #region ==dwWS===========
        public static readonly DependencyProperty dwWSProperty = DependencyProperty.Register("dwWS",
            typeof(DataRow), typeof(UIWGBST),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWSChanged));
        public DataRow dwWS
        {
            get
            {
                return (DataRow)GetValue(dwWSProperty);
            }
            set
            {
                SetValue(dwWSProperty, value);
            }
        }
        private static void OndwWSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.dwWS = (DataRow)e.NewValue;
            }
        }
        #endregion
        #region ==dwWD===========
        public static readonly DependencyProperty dwWDProperty = DependencyProperty.Register("dwWD",
            typeof(DataRow), typeof(UIWGBST),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWDChanged));
        public DataRow dwWD
        {
            get
            {
                return (DataRow)GetValue(dwWDProperty);
            }
            set
            {
                SetValue(dwWDProperty, value);
                OnWDChg(value);
            }
        }
        private static void OndwWDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.dwWD = (DataRow)e.NewValue;
                
            }
        }
        #endregion
        #region ==dwWG===========
        public static readonly DependencyProperty dwWGProperty = DependencyProperty.Register("dwWG",
            typeof(DataRow), typeof(UIWGBST),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwWGChanged));
        public DataRow dwWG
        {
            get
            {
                return (DataRow)GetValue(dwWGProperty);
            }
            set
            {
                SetValue(dwWGProperty, value);
            }
        }
        private static void OndwWGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.dwWG = (DataRow)e.NewValue;
            }
        }
        #endregion
        #region ==WGMJJ===========
        public static readonly DependencyProperty WGMJJProperty = DependencyProperty.Register("WGMJJ",
            typeof(string), typeof(UIWGBST),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWGMJJChanged));
        public string WGMJJ
        {
            get
            {
                return (string)GetValue(WGMJJProperty);
            }
            set
            {
                SetValue(WGMJJProperty, value);
            }
        }
        private static void OnWGMJJChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TWGBST;
            if (src != null)
            {
                src.WGMJJ = (string)e.NewValue;
            }
        }
        #endregion
        #region ==WGMM===========
        public static readonly DependencyProperty WGMMProperty = DependencyProperty.Register("WGMM",
            typeof(string), typeof(UIWGBST),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWGMMChanged));
        public string WGMM
        {
            get
            {
                return (string)GetValue(WGMMProperty);
            }
            set
            {
                SetValue(WGMMProperty, value);
            }
        }
        private static void OnWGMMChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.WGMM = (string)e.NewValue;
            }
        }
        #endregion
        #region ==WGLO===========
        public static readonly DependencyProperty WGLOProperty = DependencyProperty.Register("WGLO",
            typeof(string), typeof(UIWGBST),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWGLOChanged));
        public string WGLO
        {
            get
            {
                return (string)GetValue(WGLOProperty);
            }
            set
            {
                SetValue(WGLOProperty, value);
            }
        }
        private static void OnWGLOChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.WGLO = (string)e.NewValue;
            }
        }
        #endregion
        #region ==FreeQty===========
        public static readonly DependencyProperty FreeQtyProperty = DependencyProperty.Register("FreeQty",
            typeof(double), typeof(UIWGBST),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFreeQtyChanged));
        public double FreeQty
        {
            get
            {
                return (double)GetValue(FreeQtyProperty);
            }
            set
            {
                SetValue(FreeQtyProperty, value);
            }
        }
        private static void OnFreeQtyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWGBST;
            if (src != null)
            {
                src.FreeQty = (double)e.NewValue;
            }
        }
        #endregion

        public UIWGBST()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        
        }

       
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);

        }
        public virtual void OnWDChg(DataRow _dwWD)
        { 
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwWG = dwMaster;
            if (dwMaster == null)
            {
                FreeQty = 0;
                return;
            }
            FreeQty = (Convert.ToDouble(dwMaster["WGBSTA"].ToString()) - Convert.ToDouble(dwMaster["WGMEZUTEI"].ToString())) / 100;
        } 
    }
}
